<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <title>Nginx作为文件下载服务器 - 八月半的研发杂谈</title><meta name="Description" content="MidAug blog java docker hugo"><meta property="og:url" content="https://100180.xyz/posts/20190615/">
  <meta property="og:site_name" content="八月半的研发杂谈">
  <meta property="og:title" content="Nginx作为文件下载服务器">
  <meta property="og:description" content="Nginx conf 配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 server { listen 80; server_name 10.43.0.0; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the">
  <meta property="og:locale" content="en">
  <meta property="og:type" content="article">
  <meta property="article:section" content="posts">
    <meta property="article:published_time" content="2019-06-15T00:00:00+00:00">
    <meta property="article:modified_time" content="2019-06-15T00:00:00+00:00">
    <meta property="article:tag" content="Nginx">
    <meta property="article:tag" content="文件下载服务">
    <meta property="og:image" content="https://100180.xyz/images/whoami/avatar.jpg">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://100180.xyz/images/whoami/avatar.jpg"><meta name="twitter:title" content="Nginx作为文件下载服务器">
<meta name="twitter:description" content="Nginx conf 配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 server { listen 80; server_name 10.43.0.0; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the">
<meta name="application-name" content="MidAug&#39;s  Blog">
<meta name="apple-mobile-web-app-title" content="MidAug&#39;s  Blog"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
        <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5"><link rel="manifest" href="/site.webmanifest"><link rel="canonical" href="https://100180.xyz/posts/20190615/" /><link rel="prev" href="https://100180.xyz/posts/2018081401/" /><link rel="next" href="https://100180.xyz/posts/20190723/" /><link rel="stylesheet" href="/css/style.min.css"><link rel="preload" href="/lib/fontawesome-free/all.min.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
        <noscript><link rel="stylesheet" href="/lib/fontawesome-free/all.min.css"></noscript><link rel="preload" href="/lib/animate/animate.min.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
        <noscript><link rel="stylesheet" href="/lib/animate/animate.min.css"></noscript><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "Nginx作为文件下载服务器",
        "inLanguage": "en",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/100180.xyz\/posts\/20190615\/"
        },"image": [{
                            "@type": "ImageObject",
                            "url": "https:\/\/100180.xyz\/images\/Apple-Devices-Preview.png",
                            "width":  3200 ,
                            "height":  2048 
                        }],"genre": "posts","keywords": "Nginx, 文件下载服务","wordcount":  925 ,
        "url": "https:\/\/100180.xyz\/posts\/20190615\/","datePublished": "2019-06-15T00:00:00+00:00","dateModified": "2019-06-15T00:00:00+00:00","license": "This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.","publisher": {
            "@type": "Organization",
            "name": "MidAug","logo": "https:\/\/100180.xyz\/images\/whoami\/avatar.jpg"},"author": {
                "@type": "Person",
                "name": "MidAug"
            },"description": ""
    }
    </script></head>
    <body data-header-desktop="fixed" data-header-mobile="auto"><script type="text/javascript">(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('auto' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'auto' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="八月半的研发杂谈"><img
        class="lazyload logo"
        src="/svg/loading.min.svg"
        data-src="/favicon/apple-icon-60x60.png"
        data-srcset="/favicon/apple-icon-60x60.png, /favicon/apple-icon-60x60.png 1.5x, /favicon/apple-icon-60x60.png 2x"
        data-sizes="auto"
        alt="/favicon/apple-icon-60x60.png"
        title="/favicon/apple-icon-60x60.png" /><span id="id-1" class="typeit"></span></a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> Posts </a><a class="menu-item" href="/tags/"> Tags </a><a class="menu-item" href="/categories/"> Categories </a><a class="menu-item" href="/about/"> About </a><a class="menu-item" href="/disclaimer/"> Disclaimer </a><a class="menu-item" href="https://github.com/midaug" title="GitHub" rel="noopener noreffer" target="_blank"><i class='fab fa-github fa-fw' aria-hidden='true'></i>  </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="Search titles or contents..." id="search-input-desktop">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-desktop" title="Search">
                            <i class="fas fa-search fa-fw" aria-hidden="true"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-desktop" title="Clear">
                            <i class="fas fa-times-circle fa-fw" aria-hidden="true"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin" aria-hidden="true"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="Switch Theme">
                    <i class="fas fa-adjust fa-fw" aria-hidden="true"></i>
                </a></div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="八月半的研发杂谈"><img
        class="lazyload logo"
        src="/svg/loading.min.svg"
        data-src="/favicon/apple-icon-60x60.png"
        data-srcset="/favicon/apple-icon-60x60.png, /favicon/apple-icon-60x60.png 1.5x, /favicon/apple-icon-60x60.png 2x"
        data-sizes="auto"
        alt="/favicon/apple-icon-60x60.png"
        title="/favicon/apple-icon-60x60.png" /><span id="id-2" class="typeit"></span></a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="Search titles or contents..." id="search-input-mobile">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-mobile" title="Search">
                            <i class="fas fa-search fa-fw" aria-hidden="true"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-mobile" title="Clear">
                            <i class="fas fa-times-circle fa-fw" aria-hidden="true"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin" aria-hidden="true"></i>
                        </span>
                    </div>
                    <a href="javascript:void(0);" class="search-cancel" id="search-cancel-mobile">
                        Cancel
                    </a>
                </div><a class="menu-item" href="/posts/" title="">Posts</a><a class="menu-item" href="/tags/" title="">Tags</a><a class="menu-item" href="/categories/" title="">Categories</a><a class="menu-item" href="/about/" title="">About</a><a class="menu-item" href="/disclaimer/" title="">Disclaimer</a><a class="menu-item" href="https://github.com/midaug" title="GitHub" rel="noopener noreffer" target="_blank"><i class='fab fa-github fa-fw' aria-hidden='true'></i></a><a href="javascript:void(0);" class="menu-item theme-switch" title="Switch Theme">
                <i class="fas fa-adjust fa-fw" aria-hidden="true"></i>
            </a></div>
    </div>
</header><div class="search-dropdown desktop">
        <div id="search-dropdown-desktop"></div>
    </div>
    <div class="search-dropdown mobile">
        <div id="search-dropdown-mobile"></div>
    </div><main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">Contents</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single"><h1 class="single-title animate__animated animate__flipInX">Nginx作为文件下载服务器</h1><div class="post-meta">
            <div class="post-meta-line"><span class="post-author"><a href="/" title="Author" rel="author" class="author"><i class="fas fa-user-circle fa-fw" aria-hidden="true"></i>MidAug</a></span>&nbsp;<span class="post-category">included in <a href="/categories/nginx/"><i class="far fa-folder fa-fw" aria-hidden="true"></i>Nginx</a></span></div>
            <div class="post-meta-line"><i class="far fa-calendar-alt fa-fw" aria-hidden="true"></i>&nbsp;<time datetime="2019-06-15">2019-06-15</time>&nbsp;<i class="fas fa-pencil-alt fa-fw" aria-hidden="true"></i>&nbsp;925 words&nbsp;
                <i class="far fa-clock fa-fw" aria-hidden="true"></i>&nbsp;2 minutes&nbsp;</div>
        </div><div class="details toc" id="toc-static"  data-kept="">
                <div class="details-summary toc-title">
                    <span>Contents</span>
                    <span><i class="details-icon fas fa-angle-right" aria-hidden="true"></i></span>
                </div>
                <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li>
      <ul>
        <li><a href="#nginx-conf-配置">Nginx conf 配置</a></li>
        <li><a href="#配置basic-auth权限认证">配置Basic Auth权限认证</a></li>
        <li><a href="#优化显示页面">优化显示页面</a></li>
      </ul>
    </li>
  </ul>
</nav></div>
            </div><div class="content" id="content"><h1 id="heading"></h1>
<h3 id="nginx-conf-配置">Nginx conf 配置</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span><span class="lnt">35
</span><span class="lnt">36
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">server <span class="o">{</span>
</span></span><span class="line"><span class="cl">    listen      80<span class="p">;</span>
</span></span><span class="line"><span class="cl">    server_name  10.43.0.0<span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="c1">#charset koi8-r;</span>
</span></span><span class="line"><span class="cl">    <span class="c1">#access_log  /var/log/nginx/log/host.access.log  main;</span>
</span></span><span class="line"><span class="cl">    location / <span class="o">{</span>
</span></span><span class="line"><span class="cl">        root  /usr/share/nginx/html<span class="p">;</span>
</span></span><span class="line"><span class="cl">        index  index.html index.htm<span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="o">}</span>
</span></span><span class="line"><span class="cl">    <span class="c1">#error_page  404              /404.html;</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># redirect server error pages to the static page /50x.html</span>
</span></span><span class="line"><span class="cl">    <span class="c1">#</span>
</span></span><span class="line"><span class="cl">    error_page  <span class="m">500</span> <span class="m">502</span> <span class="m">503</span> <span class="m">504</span>  /50x.html<span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="nv">location</span> <span class="o">=</span> /50x.html <span class="o">{</span>
</span></span><span class="line"><span class="cl">        root  /usr/share/nginx/html<span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="o">}</span>
</span></span><span class="line"><span class="cl">    location /build_results/ <span class="o">{</span>
</span></span><span class="line"><span class="cl">        proxy_set_header Host <span class="nv">$http_host</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">        root  /data/jenkins/<span class="p">;</span>
</span></span><span class="line"><span class="cl">        index  index.html index.htm<span class="p">;</span>
</span></span><span class="line"><span class="cl">        autoindex on<span class="p">;</span> <span class="c1"># 开启目录文件列表</span>
</span></span><span class="line"><span class="cl">        autoindex_exact_size off<span class="p">;</span> <span class="c1"># 显示出文件的确切大小，单位是bytes</span>
</span></span><span class="line"><span class="cl">        autoindex_localtime on<span class="p">;</span> <span class="c1"># 显示的文件时间为文件的服务器时间</span>
</span></span><span class="line"><span class="cl">        charset utf-8,gbk<span class="p">;</span> <span class="c1"># 避免中文乱码</span>
</span></span><span class="line"><span class="cl">        <span class="c1">#add_after_body /autoindex.html; #添加html内容， 此文件应放置在 location / 配置的 root目录下</span>
</span></span><span class="line"><span class="cl">        <span class="c1">#add_before_body /autoindex.html;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">        <span class="c1">#auth_basic &#34;Restricted&#34;; #启用账号密码限制  #这里是验证时的提示信息</span>
</span></span><span class="line"><span class="cl">        <span class="c1">#auth_basic_user_file /etc/nginx/passwd; #这里是密码文件</span>
</span></span><span class="line"><span class="cl">        <span class="c1">#limit_conn one 8;        #并发数</span>
</span></span><span class="line"><span class="cl">        <span class="c1">#limit_rate 100k;        #单个线程最大下载速度，单位KB/s</span>
</span></span><span class="line"><span class="cl">        <span class="c1">#allow 192.168.1.0/24;    #添加允许访问下载 IP 地址段</span>
</span></span><span class="line"><span class="cl">        <span class="c1">#allow 172.17.0.0/16;</span>
</span></span><span class="line"><span class="cl">        <span class="c1">#deny  all; #禁用其他</span>
</span></span><span class="line"><span class="cl">    <span class="o">}</span>
</span></span><span class="line"><span class="cl"><span class="o">}</span>
</span></span></code></pre></td></tr></table>
</div>
</div><!-- more -->
<h3 id="配置basic-auth权限认证">配置Basic Auth权限认证</h3>
<p>我们需要htpassword来创建和生成加密的用户用于基础认证(Basic Authentication)
ubuntu 安装 sudo apt-get install apache2-utils</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">htpasswd 命令参数
</span></span><span class="line"><span class="cl">-c 创建passwdfile.如果passwdfile 已经存在,那么它会重新写入并删去原有内容.
</span></span><span class="line"><span class="cl">-n 不更新passwordfile，直接显示密码
</span></span><span class="line"><span class="cl">-m 使用MD5加密（默认）
</span></span><span class="line"><span class="cl">-d 使用CRYPT加密（默认）
</span></span><span class="line"><span class="cl">-p 使用普通文本格式的密码
</span></span><span class="line"><span class="cl">-s 使用SHA加密
</span></span><span class="line"><span class="cl">-b 命令行中一并输入用户名和密码而不是根据提示输入密码，可以看见明文，不需要交互
</span></span><span class="line"><span class="cl">-D 删除指定的用户
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">sudo htpasswd -c /etc/nginx/passwd Postgres <span class="c1">#创建密码文件以及用户名=</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">#/etc/nginx/passwd 文件格式如下:</span>
</span></span><span class="line"><span class="cl">loginuser:password
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">#Nginx配置文件新增内容:</span>
</span></span><span class="line"><span class="cl">location /secret <span class="o">{</span>
</span></span><span class="line"><span class="cl">    auth_basic <span class="s2">&#34;Please input password&#34;</span><span class="p">;</span> <span class="c1">#这里是验证时的提示信息</span>
</span></span><span class="line"><span class="cl">    auth_basic_user_file /etc/nginx/passwd<span class="p">;</span> <span class="c1"># 创建的passwd文件</span>
</span></span><span class="line"><span class="cl"><span class="o">}</span>
</span></span></code></pre></td></tr></table>
</div>
</div><h3 id="优化显示页面">优化显示页面</h3>
<p>对日期进行格式化，并添加导航路径
#add_after_body /autoindex.html; #添加html内容， 此文件应放置在 location / 配置的 root目录下</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span><span class="lnt">35
</span><span class="lnt">36
</span><span class="lnt">37
</span><span class="lnt">38
</span><span class="lnt">39
</span><span class="lnt">40
</span><span class="lnt">41
</span><span class="lnt">42
</span><span class="lnt">43
</span><span class="lnt">44
</span><span class="lnt">45
</span><span class="lnt">46
</span><span class="lnt">47
</span><span class="lnt">48
</span><span class="lnt">49
</span><span class="lnt">50
</span><span class="lnt">51
</span><span class="lnt">52
</span><span class="lnt">53
</span><span class="lnt">54
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-javascript" data-lang="javascript"><span class="line"><span class="cl"><span class="o">&lt;</span><span class="nx">script</span><span class="o">&gt;</span>
</span></span><span class="line"><span class="cl">    <span class="kd">var</span> <span class="nx">formatDate</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">datetime</span><span class="p">,</span> <span class="nx">format</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nb">isNaN</span><span class="p">(</span><span class="nb">Date</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">datetime</span><span class="p">)))</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">            <span class="nx">d</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">(</span><span class="nx">datetime</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">            <span class="nx">pad</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">s</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="nx">s</span> <span class="o">&lt;</span> <span class="mi">10</span> <span class="o">?</span> <span class="s1">&#39;0&#39;</span> <span class="o">+</span> <span class="nx">s</span> <span class="o">:</span> <span class="nx">s</span> <span class="p">};</span>
</span></span><span class="line"><span class="cl">            <span class="nx">mon</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">m</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="p">[</span><span class="s1">&#39;Jan&#39;</span><span class="p">,</span> <span class="s1">&#39;Feb&#39;</span><span class="p">,</span> <span class="s1">&#39;Mar&#39;</span><span class="p">,</span> <span class="s1">&#39;Apr&#39;</span><span class="p">,</span> <span class="s1">&#39;May&#39;</span><span class="p">,</span> <span class="s1">&#39;Jun&#39;</span><span class="p">,</span> <span class="s1">&#39;Jul&#39;</span><span class="p">,</span> <span class="s1">&#39;Aug&#39;</span><span class="p">,</span> <span class="s1">&#39;Sep&#39;</span><span class="p">,</span> <span class="s1">&#39;Oct&#39;</span><span class="p">,</span> <span class="s1">&#39;Nov&#39;</span><span class="p">,</span> <span class="s1">&#39;Dec&#39;</span><span class="p">][</span><span class="nx">m</span><span class="p">]</span> <span class="p">};</span>
</span></span><span class="line"><span class="cl">            <span class="nx">datetime</span> <span class="o">=</span> <span class="nx">format</span>
</span></span><span class="line"><span class="cl">                <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s1">&#39;%Y&#39;</span><span class="p">,</span> <span class="nx">d</span><span class="p">.</span><span class="nx">getFullYear</span><span class="p">())</span>
</span></span><span class="line"><span class="cl">                <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s1">&#39;%m&#39;</span><span class="p">,</span> <span class="nx">pad</span><span class="p">(</span><span class="nx">d</span><span class="p">.</span><span class="nx">getMonth</span><span class="p">()</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span>
</span></span><span class="line"><span class="cl">                <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s1">&#39;%d&#39;</span><span class="p">,</span> <span class="nx">pad</span><span class="p">(</span><span class="nx">d</span><span class="p">.</span><span class="nx">getDate</span><span class="p">()))</span>
</span></span><span class="line"><span class="cl">                <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s1">&#39;%H&#39;</span><span class="p">,</span> <span class="nx">pad</span><span class="p">(</span><span class="nx">d</span><span class="p">.</span><span class="nx">getHours</span><span class="p">()))</span>
</span></span><span class="line"><span class="cl">                <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s1">&#39;%M&#39;</span><span class="p">,</span> <span class="nx">pad</span><span class="p">(</span><span class="nx">d</span><span class="p">.</span><span class="nx">getMinutes</span><span class="p">()))</span>
</span></span><span class="line"><span class="cl">                <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s1">&#39;%S&#39;</span><span class="p">,</span> <span class="nx">pad</span><span class="p">(</span><span class="nx">d</span><span class="p">.</span><span class="nx">getSeconds</span><span class="p">()))</span>
</span></span><span class="line"><span class="cl">                <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s1">&#39;%b&#39;</span><span class="p">,</span> <span class="nx">mon</span><span class="p">(</span><span class="nx">d</span><span class="p">.</span><span class="nx">getMonth</span><span class="p">()));</span>
</span></span><span class="line"><span class="cl">        <span class="p">}</span>
</span></span><span class="line"><span class="cl">        <span class="k">return</span> <span class="nx">datetime</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="p">};</span>
</span></span><span class="line"><span class="cl">    <span class="nb">window</span><span class="p">.</span><span class="nx">onload</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="kd">var</span> <span class="nx">datetime_format</span> <span class="o">=</span> <span class="s1">&#39;%Y-%m-%d %H:%M&#39;</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">        <span class="nx">setTimeout</span><span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">            <span class="kd">var</span> <span class="nx">title</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span><span class="p">(</span><span class="s2">&#34;h1&#34;</span><span class="p">)[</span><span class="mi">0</span><span class="p">];</span>
</span></span><span class="line"><span class="cl">            <span class="kd">var</span> <span class="nx">lastName</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">            <span class="kd">var</span> <span class="nx">titlehtml</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">title</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\/$/</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">).</span><span class="nx">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">).</span><span class="nx">slice</span><span class="p">(</span><span class="mi">1</span><span class="p">).</span><span class="nx">reduce</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">acc</span><span class="p">,</span> <span class="nx">v</span><span class="p">,</span> <span class="nx">i</span><span class="p">,</span> <span class="nx">a</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">                <span class="nx">lastName</span> <span class="o">=</span> <span class="nx">v</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">                <span class="k">return</span> <span class="nx">acc</span> <span class="o">+</span> <span class="s1">&#39;&lt;a href=&#34;/&#39;</span> <span class="o">+</span> <span class="nx">a</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nx">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;/&#34;&gt;&#39;</span> <span class="o">+</span> <span class="nx">v</span> <span class="o">+</span> <span class="s1">&#39;&lt;/a&gt;/&#39;</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">            <span class="p">},</span> <span class="s1">&#39;Index of /&#39;</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">            <span class="nx">title</span><span class="p">.</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="nx">titlehtml</span> <span class="o">+</span> <span class="s1">&#39;&lt;span style=&#34;margin-left: 100px;&#34;&gt;&#39;</span> <span class="o">+</span> <span class="nx">lastName</span> <span class="o">+</span> <span class="s1">&#39;&lt;/span&gt;&#39;</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">        <span class="p">},</span> <span class="mi">1</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">        <span class="nx">setTimeout</span><span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">            <span class="kd">var</span> <span class="nx">pre</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span><span class="p">(</span><span class="s2">&#34;pre&#34;</span><span class="p">)[</span><span class="mi">0</span><span class="p">];</span>
</span></span><span class="line"><span class="cl">            <span class="kd">var</span> <span class="nx">bodys</span> <span class="o">=</span> <span class="nx">pre</span><span class="p">.</span><span class="nx">innerHTML</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s2">&#34;\n&#34;</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">            <span class="kd">var</span> <span class="nx">list</span> <span class="o">=</span> <span class="p">[];</span>
</span></span><span class="line"><span class="cl">            <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">bodys</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">                <span class="kd">var</span> <span class="nx">bodyline</span> <span class="o">=</span> <span class="nx">bodys</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
</span></span><span class="line"><span class="cl">                <span class="k">if</span> <span class="p">(</span><span class="nx">m</span> <span class="o">=</span> <span class="sr">/\s*&lt;a href=&#34;(.+?)&#34;&gt;(.+?)&lt;\/a&gt;\s+(\S+)\s+(\S+)\s+(\S+)\s*/</span><span class="p">.</span><span class="nx">exec</span><span class="p">(</span><span class="nx">bodyline</span><span class="p">))</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">                    <span class="nx">filename</span> <span class="o">=</span> <span class="nx">m</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>
</span></span><span class="line"><span class="cl">                    <span class="nx">datetime</span> <span class="o">=</span> <span class="nx">m</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39; &#39;</span> <span class="o">+</span> <span class="nx">m</span><span class="p">[</span><span class="mi">4</span><span class="p">];</span>
</span></span><span class="line"><span class="cl">                    <span class="nx">size</span> <span class="o">=</span> <span class="nx">m</span><span class="p">[</span><span class="mi">5</span><span class="p">];</span>
</span></span><span class="line"><span class="cl">                    <span class="nx">list</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">bodyline</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="nx">datetime</span><span class="p">,</span> <span class="nx">formatDate</span><span class="p">(</span><span class="nx">datetime</span><span class="p">,</span> <span class="nx">datetime_format</span><span class="p">)));</span>
</span></span><span class="line"><span class="cl">                <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">                    <span class="nx">list</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">bodyline</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">                <span class="p">}</span>
</span></span><span class="line"><span class="cl">            <span class="p">}</span>
</span></span><span class="line"><span class="cl">            <span class="nx">pre</span><span class="p">.</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="nx">list</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s2">&#34;\n&#34;</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">        <span class="p">},</span> <span class="mi">1</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">    <span class="p">};</span>
</span></span><span class="line"><span class="cl"><span class="o">&lt;</span><span class="err">/script&gt;</span>
</span></span><span class="line"><span class="cl"><span class="o">&lt;</span><span class="nx">style</span><span class="o">&gt;</span>
</span></span><span class="line"><span class="cl">    <span class="nx">a</span> <span class="p">{</span><span class="nx">text</span><span class="o">-</span><span class="nx">decoration</span><span class="o">:</span> <span class="nx">none</span><span class="p">;}</span>
</span></span><span class="line"><span class="cl">    <span class="nx">a</span><span class="o">:</span><span class="nx">visited</span> <span class="p">{</span><span class="nx">text</span><span class="o">-</span><span class="nx">decoration</span><span class="o">:</span> <span class="nx">none</span><span class="p">;}</span>
</span></span><span class="line"><span class="cl">    <span class="nx">a</span><span class="o">:</span><span class="nx">hover</span> <span class="p">{</span><span class="nx">text</span><span class="o">-</span><span class="nx">decoration</span><span class="o">:</span> <span class="nx">none</span><span class="p">;}</span>
</span></span><span class="line"><span class="cl">    <span class="nx">a</span><span class="o">:</span><span class="nx">active</span> <span class="p">{</span><span class="nx">text</span><span class="o">-</span><span class="nx">decoration</span><span class="o">:</span> <span class="nx">none</span><span class="p">;}</span>
</span></span><span class="line"><span class="cl">    <span class="nx">h1</span> <span class="p">{</span><span class="nx">font</span><span class="o">-</span><span class="nx">size</span><span class="o">:</span> <span class="mi">20</span><span class="nx">px</span><span class="p">;}</span>
</span></span><span class="line"><span class="cl"><span class="o">&lt;</span><span class="err">/style&gt;</span>
</span></span></code></pre></td></tr></table>
</div>
</div></div><div class="post-footer" id="post-footer">
    <div class="post-info">
        <div class="post-info-line">
            <div class="post-info-mod">
                <span>Updated on 2019-06-15</span>
            </div></div>
        <div class="post-info-line">
            <div class="post-info-md"></div>
            <div class="post-info-share">
                <span><a href="javascript:void(0);" title="Share on Twitter" data-sharer="twitter" data-url="https://100180.xyz/posts/20190615/" data-title="Nginx作为文件下载服务器" data-hashtags="Nginx,文件下载服务"><i class="fab fa-twitter fa-fw" aria-hidden="true"></i></a><a href="javascript:void(0);" title="Share on Facebook" data-sharer="facebook" data-url="https://100180.xyz/posts/20190615/" data-hashtag="Nginx"><i class="fab fa-facebook-square fa-fw" aria-hidden="true"></i></a><a href="javascript:void(0);" title="Share on Linkedin" data-sharer="linkedin" data-url="https://100180.xyz/posts/20190615/"><i class="fab fa-linkedin fa-fw" aria-hidden="true"></i></a><a href="javascript:void(0);" title="Share on 微博" data-sharer="weibo" data-url="https://100180.xyz/posts/20190615/" data-title="Nginx作为文件下载服务器"><i class="fab fa-weibo fa-fw" aria-hidden="true"></i></a><a href="javascript:void(0);" title="Share on 百度" data-sharer="baidu" data-url="https://100180.xyz/posts/20190615/" data-title="Nginx作为文件下载服务器"><i data-svg-src="/lib/simple-icons/icons/baidu.min.svg" aria-hidden="true"></i></a><a href="javascript:void(0);" title="Share on Evernote" data-sharer="evernote" data-url="https://100180.xyz/posts/20190615/" data-title="Nginx作为文件下载服务器"><i class="fab fa-evernote fa-fw" aria-hidden="true"></i></a><a href="javascript:void(0);" title="Share on Skype" data-sharer="skype" data-url="https://100180.xyz/posts/20190615/" data-title="Nginx作为文件下载服务器"><i class="fab fa-skype fa-fw" aria-hidden="true"></i></a></span>
            </div>
        </div>
    </div>

    <div class="post-info-more">
        <section class="post-tags"><i class="fas fa-tags fa-fw" aria-hidden="true"></i>&nbsp;<a href="/tags/nginx/">Nginx</a>,&nbsp;<a href="/tags/%E6%96%87%E4%BB%B6%E4%B8%8B%E8%BD%BD%E6%9C%8D%E5%8A%A1/">文件下载服务</a></section>
        <section>
            <span><a href="javascript:void(0);" onclick="window.history.back();">Back</a></span>&nbsp;|&nbsp;<span><a href="/">Home</a></span>
        </section>
    </div>

    <div class="post-nav"><a href="/posts/2018081401/" class="prev" rel="prev" title="CSS自定义滚动条(IE和chrome)"><i class="fas fa-angle-left fa-fw" aria-hidden="true"></i>CSS自定义滚动条(IE和chrome)</a>
            <a href="/posts/20190723/" class="next" rel="next" title="ubuntu下RabbitMQ安装及集群配置">ubuntu下RabbitMQ安装及集群配置<i class="fas fa-angle-right fa-fw" aria-hidden="true"></i></a></div>
</div>
</article></div>
            </main><footer class="footer">
        <div class="footer-container"><div class="footer-line" itemscope itemtype="http://schema.org/CreativeWork"><i class="far fa-copyright fa-fw" aria-hidden="true"></i><span itemprop="copyrightYear">2017 - 2025</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/" target="_blank">MidAug</a></span>&nbsp;|&nbsp;<span class="license"><a rel="license external nofollow noopener noreffer" href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank">CC BY-NC 4.0</a></span><span class="icp-splitter">&nbsp;|&nbsp;</span><br class="icp-br"/>
                    <span class="icp"><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7196301099178927" crossorigin="anonymous"></script> <a target=_blank href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=31011502019261"><img style="vertical-align: text-bottom; height: 1rem" class="lazyload" data-src="/beian/gongan.png"><span>沪公网安备 31011502019261号</span></a><span class="icp-splitter">&nbsp;|&nbsp;</span><a href="https://beian.miit.gov.cn/" target="_blank">沪ICP备2022026688号-1</a></span></div>
        </div>
    </footer></div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="Back to Top">
                <i class="fas fa-arrow-up fa-fw" aria-hidden="true"></i>
            </a><a href="#" id="view-comments" class="fixed-button" title="View Comments">
                <i class="fas fa-comment fa-fw" aria-hidden="true"></i>
            </a>
        </div><script type="text/javascript" src="/lib/autocomplete/autocomplete.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.min.js"></script><script type="text/javascript" src="/lib/lazysizes/lazysizes.min.js"></script><script type="text/javascript" src="/lib/clipboard/clipboard.min.js"></script><script type="text/javascript" src="/lib/sharer/sharer.min.js"></script><script type="text/javascript" src="/lib/typeit/index.umd.js"></script><script type="text/javascript">window.config={"code":{"copyTitle":"Copy to clipboard","maxShownLines":50},"comment":{},"data":{"id-1":"八月半的研发杂谈","id-2":"八月半的研发杂谈"},"search":{"highlightTag":"em","lunrIndexURL":"/index.json","maxResultLength":10,"noResultsFound":"No results found","snippetLength":80,"type":"lunr"},"typeit":{"cursorChar":"|","cursorSpeed":1000,"data":{"id-1":["id-1"],"id-2":["id-2"]},"duration":-1,"speed":30}};</script><script type="text/javascript" src="/js/theme.min.js"></script></body>
</html>
